<?php
/**
 * XmuSlh, web platform of Student Association Federation of Xiamen University
 * 
 * Rewritting one or some pages of StatusNet. 
 * To get the original version, please visit <http://status.net/>.
 * 
 * StatusNet, the distributed open-source microblogging tool
 * 
 * LICENCE: This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * Widgets for displaying a list of editing association users.
 * Includes a list widget and its specific item widget.
 * 
 * @see slh_list_showprofileuser.php
 * 
 * @author		ytukie <ytukie@gmail.com>
 * @version		0.5
 * 
 * 0.2)  Inherited from the BaseList and BaseListItem
 * 0.3)  Changes its original name added with 'user'.
 * 0.4)  Changes the style, unstable.
 * 0.5)  Adds some rights hanlders.
 */

// XmuSlh only.
if ( !defined('XMUSLH')) { exit(1); }

// Requirements.
require_once INSTALLDIR . '/lib/slh_list.php';

require_once INSTALLDIR . '/classes/Avatar.php';
require_once INSTALLDIR . '/classes/Association.php';


/**
 * Widget for displaying a list of associations.
 */
class AssociationList extends BaseList
{
	/**
	 * Overrided.
	 * Starts a association user list.
	 */
	function showStart()
	{
		// The List title.
		$this->out->element('h3', null, '社团™');
		$this->out->elementStart('ol', array('class' => 'cls_ol_list'));
		
		$this->out->element('hr');
	}
	
	/**
	 * Ends a list.
	 */
	function showEnd()
	{
		$this->out->elementEnd('ol');
	}
	
	/**
	 * Overrided.
	 * Returns a list item for the current association user.
	 */
	function newListItem(&$obj)
	{
		return new AssociationListItem($obj, $this->out);
	}
}

/**
 * Widget for displaying a single association with some options.
 */
class AssociationListItem extends BaseListItem
{
	/**
	 * Tiny avatar url.
	 */
	var $avatarurl;
	
	/**
	 * The url of the association.
	 */
	var $associationurl = null;
	
	/**
	 * Overrided.
	 */
	function prepareData()
	{
// FIXME: The relationship with the user.
		$avatar = Avatar::getAvatarBySize($this->obj->user_id, AVATAR_TINY_SIZE);
		if ( !empty($avatar)) {
			$this->avatarurl = $avatar->avatarurl();
		} else {
			$this->avatarurl = Avatar::defaultImage(AVATAR_TINY_SIZE);
		}
		
		$this->associationurl = slh_action2url('association', array('guser_id' => $this->obj->user_id));
		
		$this->optionswitch = Rights::hasRight(slh_get_userrights(), RIGHT_ASSOCITION);
	}
	
	/**
	 * Overrided.
	 */
	function showStart()
	{
		$this->out->elementStart('li', array('class' => 'cls_div_entry'));
	}
	
	function showEnd()
	{
		$this->out->elementEnd('li');
		
		$this->out->element('hr');
	}
	
	function showDataInfo()
	{
		$this->out->elementStart('div', array('class' => 'cls_div_miniavatar'));
		$this->out->element('img', array('src' => $this->avatarurl));
		$this->out->elementEnd('div');
		
		$this->out->elementStart('div', 'cls_div_block');
			$this->out->elementStart('a', array('href' => $this->associationurl,
												'target' => '_blank'));
			$this->out->raw('<span class="cls_span_name">' .
							$this->obj->cnname .
							'</span>');
			$this->out->elementEnd('a');
			
			$this->out->raw('<span class="cls_span_catagroy">' .
							$this->obj->getCatagoryName() .
							'</span>');
		$this->out->elementEnd('div');
	}
	
	function showOptions()
	{
		$this->out->elementStart('div', 'cls_div_associationoptions');
		
		$this->out->elementStart('ul', array('class' => 'cls_ul_inline'));
			$this->out->elementStart('li');
			$this->out->element('a', array('href' => slh_action2url('editassociationuser',
								  	   							  	array('guser_id' => $this->obj->user_id)),
										   'title'=> '编辑该用户!'),
								'编辑');
			$this->out->elementEnd('li');
			
			if (true) {
			$this->out->elementStart('li');
			$this->out->element('a', array('href' => slh_action2url('deleteassociationuser',
								  	   							  	array('guser_id' => $this->obj->user_id)),
										   'title'=> '把这个用户删掉哈!'),
								'删除');
			$this->out->elementEnd('li');
			}
		$this->out->elementEnd('ul');
		
		$this->out->elementEnd('div');
	}
	
}

?>